package com.aaa.qy127.service.impl;

import com.aaa.qy127.dao.RukuDao;
import com.aaa.qy127.dao.impl.RukuDaoImpl;
import com.aaa.qy127.entity.Ruku;
import com.aaa.qy127.entity.Staff;
import com.aaa.qy127.service.RukuService;
import com.aaa.qy127.util.Result;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RukuServiceImpl implements RukuService {
    RukuDao rukuDao = new RukuDaoImpl();
    /**
     * 查询入库信息
     * @param ruku
     * @return
     */
    @Override
    public Result queryAllruku(Ruku ruku) {
        List<Map<String, Object>> list = rukuDao.queryAllruku(ruku);
        int count = rukuDao.getAllCount(ruku);
        Result result = new Result(count, list);
        return result;
    }
    /**
     * 查询一条入库信息详情
     * @param ruku
     * @return
     */
    @Override
    public Result getoneruku(Ruku ruku) {
        List<Map<String, Object>> list = rukuDao.getoneruku(ruku);
        int count = rukuDao.getoneCount(ruku);
        Result result = new Result(count, list);
        return result;
    }
    /**
     * 添加入库单
     * @param map
     * @param maps
     * @param uid
     * @return
     */
    @Override
    public String addruku(HashMap map, List<Map<String,Object>> maps, Integer uid) {
        double totalprice=Double.valueOf(map.get("totalprice").toString());
        Integer totalcount=Integer.valueOf(map.get("totalcount").toString());
        int rukuid = rukuDao.addruku(uid, totalprice, totalcount, (String) map.get("jsr"));
        int a = 0;
        for (int i = 0; i < maps.size(); i++) {
            double price=Double.valueOf(maps.get(i).get("price").toString());
            Integer bookid=Integer.valueOf(maps.get(i).get("bookid").toString());
            Integer count=Integer.valueOf(maps.get(i).get("count").toString());
            int addrukuxiangqing = rukuDao.addrukuxiangqing(bookid, count, rukuid, price);
            a = addrukuxiangqing;
        }
        if (a>0){
            return "1001";
        }else {
            return "1002";
        }
    }
}
